﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test_ProDivingAdmin2salmon14
{
    public class Dive
    {
        public string diveCode { get; set; }
        public List<Tuple<string,float>> judgeScores { get; set; }
        public float diveScore { get; set; }

        public Dive()
        {
            this.diveScore = 0;
            this.judgeScores = new List<Tuple<string, float>>();
        }

        public Dive(string diveCode)
        {
            this.diveCode = diveCode;
            this.diveScore = 0;
            this.judgeScores = new List<Tuple<string, float>>();
        }


        public void CalculateScore()
        {
            this.diveScore = 0;
            Tuple<string,float> max = new Tuple<string,float>("",0);
            Tuple<string,float> min = new Tuple<string,float>("",10);
            foreach (var judgeScore in this.judgeScores)
            {
                if (judgeScore.Item2 > max.Item2)
                {
                    max = judgeScore;
                }
                if (judgeScore.Item2 < min.Item2)
                {
                    min = judgeScore;
                }

                this.diveScore += judgeScore.Item2;
            }

            this.diveScore -= max.Item2;
            this.diveScore -= min.Item2;

            

            if (this.diveScore < 0)
            {
                this.diveScore = 0;
            }
            this.diveScore *= this.GetDifficulty();
        }

        public float GetDifficulty() 
        {
            float difficulty;
            try
            {
                difficulty = Contest.validDives[this.diveCode].Item1;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                
            }
            return difficulty;
        }

        public string GetName() 
        {
            return FileManager.diveList[this.diveCode].Item2;
        }
    }
}
